package com.domino.server.persistence.playeraudit;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;

import com.domino.server.cache.GameSessionData;
import com.domino.shared.PlayerId;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@Entity
public class PlayerDO {

	@Id
	private Key id;
	
	private String nickname;
	
	private int accessed = 0;
	private int startBot = 0;
	private int endBot = 0;
	private int startOpponent = 0;
	private int endOpponent = 0;
	private int leaveGame = 0; 
	private Date lastUpdated;

	public PlayerDO(String id, String nickname) {
		Key key = KeyFactory.createKey(PlayerDO.class.getSimpleName(), Long.parseLong(id));
		this.id = key;
		this.nickname = nickname;
	}

	public void incrementAccess() {
		accessed++;
		lastUpdated = new Date();
	}

	public Key getId() {
		return id;
	}

	public void setId(Key id) {
		this.id = id;
	}
	

	public int getLeaveGame() {
		return leaveGame;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public int getAccessed() {
		return accessed;
	}

	public int getStartBot() {
		return startBot;
	}

	public int getEndBot() {
		return endBot;
	}

	public int getStartOpponent() {
		return startOpponent;
	}

	public int getEndOpponent() {
		return endOpponent;
	}

	public Date getLastUpdated() {
		return lastUpdated;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PlayerDO other = (PlayerDO) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	

	@Override
	public String toString() {
		return "PlayerDO [id=" + id + ", nickname=" + nickname + ", accessed="
				+ accessed + ", startBot=" + startBot + ", endBot=" + endBot
				+ ", startOpponent=" + startOpponent + ", endOpponent="
				+ endOpponent + ", leaveGame=" + leaveGame + ", lastUpdated="
				+ lastUpdated + "]";
	}

	public void incrementBotStart() {
		this.startBot++;
	}

	public void incrementBotEnd() {
		this.endBot++;
	}

	public void incrementOpponentStart() {
		this.startOpponent++;
	}

	public void incrementOpponentEnd() {
		this.endOpponent++;
	}

	public void incrementLeaveGame() {
		this.leaveGame++;
	}

	

}
